package cn.neusoft.jdkproxy;

import cn.neusoft.cglib.OrderService;
import cn.neusoft.staticproxy.EmpService;
import cn.neusoft.staticproxy.IEmpService;

public class JdkProxyTest {

    public static void main(String[] args) {
        IUserService target = new UserService();

        //创建代理工厂
        ProxyFactory factory = new ProxyFactory();
        //将目标类对象设置给代理工厂
        factory.setTarget(target);
        //工厂生成代理对象   （强转为代理的类型）
        IUserService proxy = (IUserService)factory.getProxy();

        System.out.println(proxy.getClass());  //class jdk.proxy1.$Proxy0

        proxy.add();
        System.out.println("-----------------");
        proxy.update();
        System.out.println("-----------------");
        proxy.getById();
        System.out.println("-----------------");
        System.out.println(proxy.toString());


        System.out.println("*************代理工厂-静态代理实现**************");

        IEmpService target2 = new EmpService();

        factory.setTarget(target2);

        IEmpService empProxy = (IEmpService)factory.getProxy();

        empProxy.add();
        System.out.println("--------------");
        empProxy.update();

        System.out.println("*************cglib未实现接口的代理实现(不可实现)****************");
        OrderService target3 = new OrderService();
        factory.setTarget(target3);
        OrderService orderProxy = (OrderService) factory.getProxy();
        orderProxy.add();
        orderProxy.update();
    }

}
